package org.robot.utils;

import java.io.File;

public class FileUtil {

    /**
     * 返回.html结尾的文件
     * @param url
     * @param type
     * @param baseDirectory 
     * @return
     */
    public static File destFile(String url, String type, String baseDirectory) {
        String md5Url = MD5.getMD5(url);
        String tag = md5Url.substring(0, 6).replaceAll("\\d", "0").replaceAll("[A-Z]", "A");
        return new File(baseDirectory + "/" + type + "/" + tag, md5Url + ".html");
    }
    
    /**
     * 适用于原来老程序的文件夹命名
     * @author pdz
     * @date 2018年11月19日
     * @param url
     * @param type
     * @param baseDirectory
     * @return
     */
    public static File destFile_origin(String url, String type, String baseDirectory) {
    	String md5Url = MD5.getMD5(url);
    	String tag1 = md5Url.substring(0, 3).replaceAll("\\d", "0").replaceAll("[A-Z]", "A");
    	String tag2 = md5Url.substring(md5Url.length()-3, md5Url.length()).replaceAll("\\d", "0").replaceAll("[A-Z]", "A");
    	String tag = tag1 + tag2;
    	return new File(baseDirectory + "/" + type + "/" + tag, md5Url + ".html");
    }
    
    public static void main(String[] args) {
		File destFile = destFile("http://ascopubs.org/doi/full/10.1200/JCO.2018.78.9602", "paper", "E:/webSpider/ascopubss");
		System.out.println(destFile.getAbsolutePath());
	}
}
